package cn.tedu.review;

import java.util.Arrays;

/**
 * 该类用于复习数组
 *
 * @author ：Dsi
 * @date ：2021/11/5 9:12
 */
public class TestArray {
    public static void main(String[] args) {
        int[] a = new int[]{1, 2, 3, 4, 5};
        int[] a1 = {1, 2, 3, 4, 5};
        int[] a2 = new int[5];
        a2[0] = 1;
        a2[1] = 2;
        a2[2] = 3;
        a2[3] = 4;
        a2[4] = 5;
        System.out.println(Arrays.toString(a2));
        //遍历赋值
        for (int b = 0; b < a2.length; b++) {
            a2[b] = b + 5;
        }
        //扩容
        int[] a3 = Arrays.copyOf(a2, 6);
        a3[5] = 10;
        System.out.println(Arrays.toString(a3));
        //缩容
        int[] a4 = Arrays.copyOf(a2, 4);
        System.out.println(Arrays.toString(a4));
        //截取
        int[] a5 = Arrays.copyOfRange(a2, 2, 4);
        System.out.println(Arrays.toString(a5));
        //遍历打印
        for (int b = 0; b < a1.length; b++) {
            System.out.println("a1数组的第" + (b + 1) + "个元素的值为：" + a1[b]);
        }
        //数组工具，Arrays.sort，排序
        int[] b = {1, 89, 6, 41, 3};
        System.out.println(Arrays.toString(b));
        Arrays.sort(b);
        System.out.println(Arrays.toString(b));
    }
}
